const common = reuire('./common.js');

/**
 * 定义聊天消息
 * @param {*} app 
 */
module.exports = app => {
  const {INTEGER, STRING } = app.Sequelize;
  return app
    .model
    .define('message', {
      id: {
        type: INTEGER,
        primaryKey: true,
        autoIncrement: true
      },
      type: {
        type: STRING,
        comment: '消息类型：0 -> 纯文本, 1 => 图片，2 => 视频，3 => 音频'
      },
      content: {
        type: STRING,
        comment: '消息内容'
      },
      avatar: {
        type: STRING,
        comment: '用户头像'
      },
      s_user: {
        type: INTEGER,
        comment: '发送者'
      },
      r_user: {
        type: INTEGER,
        comment: '接收者'
      },
      is_read: {
        type: INTEGER,
        comment: '阅读状态: 0 -> 未读，1 -> 已读'
      },
      ...common
    }, {
      timestamps: false,
      freezeTableName: true,
      tableName: 't_msg',
      underscored: true
    }
  );
};